package cz.proks.easyhelpdesk.gae.api.impl.dbo;

import org.springframework.beans.BeanUtils;

import cz.proks.easyhelpdesk.gae.api.impl.dbo.base.ConvertibleDbo;
import cz.proks.easyhelpdesk.gae.api.impl.dbo.base.IdentifiableHelpdeskModelDbo;

public class Category extends cz.proks.easyhelpdesk.api.model.Category implements IdentifiableHelpdeskModelDbo, ConvertibleDbo<cz.proks.easyhelpdesk.api.model.Category> {
    private Helpdesk helpdesk;
    
    @Override
    public Long getHelpdeskId() {    
        return super.getHelpdeskId();
    }

    @Override
    public void setHelpdeskId(Long helpdeskId) {
        super.setHelpdeskId(helpdeskId);
        
        if (helpdeskId == null)
            helpdesk = null;            
        else {
            helpdesk = new Helpdesk();        
            helpdesk.setId(helpdeskId);
        }                           
    }

    @Override
    public Helpdesk getHelpdesk() {
        return helpdesk;
    }    
  
    @Override
    public void setHelpdesk(Helpdesk helpdesk) {
        this.helpdesk = helpdesk;
        super.setHelpdeskId(helpdesk != null ? helpdesk.getId() : null);
    }    
    
    public void toDbo(cz.proks.easyhelpdesk.api.model.Category category) {
        BeanUtils.copyProperties(category, this);
    }
    
    public cz.proks.easyhelpdesk.api.model.Category asDomain() {
        cz.proks.easyhelpdesk.api.model.Category category = new cz.proks.easyhelpdesk.api.model.Category();
        BeanUtils.copyProperties(this, category);        
        return category;
    }         
}
